﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;
namespace Chenxin.Lib.Business.DAL
{
    /// <summary>
    /// 数据访问类t_Business_NotLitigationInfo。
    /// </summary>
    public class t_Business_NotLitigationInfo
    {
        public t_Business_NotLitigationInfo()
        { }
        #region  成员方法

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.Business.Entity.t_Business_NotLitigationInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_Business_NotLitigationInfo(");
            strSql.Append("RecordId,ContractId,ContractCode,HasAttachment,HouseAddress,AppCityId,AppCity,AppCompanyId,AppCompany,AppDepartId,AppDepart,AcceptedDate,MailDate,Description,Memo,AddTime,AddPersonId,AddPerson)");

            strSql.Append(" values (");
            strSql.Append("@RecordId,@ContractId,@ContractCode,@HasAttachment,@HouseAddress,@AppCityId,@AppCity,@AppCompanyId,@AppCompany,@AppDepartId,@AppDepart,@AcceptedDate,@MailDate,@Description,@Memo,@AddTime,@AddPersonId,@AddPerson)");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "ContractId", DbType.Guid, model.ContractId);
            db.AddInParameter(dbCommand, "ContractCode", DbType.AnsiString, model.ContractCode);
            db.AddInParameter(dbCommand, "HasAttachment", DbType.Int32, model.HasAttachment);
            db.AddInParameter(dbCommand, "HouseAddress", DbType.AnsiString, model.HouseAddress);
            db.AddInParameter(dbCommand, "AppCityId", DbType.Guid, model.AppCityId);
            db.AddInParameter(dbCommand, "AppCity", DbType.AnsiString, model.AppCity);
            db.AddInParameter(dbCommand, "AppCompanyId", DbType.Guid, model.AppCompanyId);
            db.AddInParameter(dbCommand, "AppCompany", DbType.AnsiString, model.AppCompany);
            db.AddInParameter(dbCommand, "AppDepartId", DbType.Guid, model.AppDepartId);
            db.AddInParameter(dbCommand, "AppDepart", DbType.AnsiString, model.AppDepart);
            db.AddInParameter(dbCommand, "AcceptedDate", DbType.DateTime, model.AcceptedDate);
            db.AddInParameter(dbCommand, "MailDate", DbType.DateTime, model.MailDate);
            db.AddInParameter(dbCommand, "Description", DbType.AnsiString, model.Description);
            db.AddInParameter(dbCommand, "Memo", DbType.AnsiString, model.Memo);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "AddPersonId", DbType.Guid, model.AddPersonId);
            db.AddInParameter(dbCommand, "AddPerson", DbType.AnsiString, model.AddPerson);
            db.ExecuteNonQuery(dbCommand);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.Business.Entity.t_Business_NotLitigationInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_Business_NotLitigationInfo set ");
            strSql.Append("ContractId=@ContractId,");
            strSql.Append("ContractCode=@ContractCode,");
            strSql.Append("HasAttachment=@HasAttachment,");
            strSql.Append("HouseAddress=@HouseAddress,");
            strSql.Append("AppCityId=@AppCityId,");
            strSql.Append("AppCity=@AppCity,");
            strSql.Append("AppCompanyId=@AppCompanyId,");
            strSql.Append("AppCompany=@AppCompany,");
            strSql.Append("AppDepartId=@AppDepartId,");
            strSql.Append("AppDepart=@AppDepart,");
            strSql.Append("AcceptedDate=@AcceptedDate,");
            strSql.Append("MailDate=@MailDate,");
            strSql.Append("Description=@Description,");
            strSql.Append("Memo=@Memo,");
            strSql.Append("AddTime=@AddTime,");
            strSql.Append("AddPersonId=@AddPersonId,");
            strSql.Append("AddPerson=@AddPerson");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "ContractId", DbType.Guid, model.ContractId);
            db.AddInParameter(dbCommand, "ContractCode", DbType.AnsiString, model.ContractCode);
            db.AddInParameter(dbCommand, "HasAttachment", DbType.Int32, model.HasAttachment);
            db.AddInParameter(dbCommand, "HouseAddress", DbType.AnsiString, model.HouseAddress);
            db.AddInParameter(dbCommand, "AppCityId", DbType.Guid, model.AppCityId);
            db.AddInParameter(dbCommand, "AppCity", DbType.AnsiString, model.AppCity);
            db.AddInParameter(dbCommand, "AppCompanyId", DbType.Guid, model.AppCompanyId);
            db.AddInParameter(dbCommand, "AppCompany", DbType.AnsiString, model.AppCompany);
            db.AddInParameter(dbCommand, "AppDepartId", DbType.Guid, model.AppDepartId);
            db.AddInParameter(dbCommand, "AppDepart", DbType.AnsiString, model.AppDepart);
            db.AddInParameter(dbCommand, "AcceptedDate", DbType.DateTime, model.AcceptedDate);
            db.AddInParameter(dbCommand, "MailDate", DbType.DateTime, model.MailDate);
            db.AddInParameter(dbCommand, "Description", DbType.AnsiString, model.Description);
            db.AddInParameter(dbCommand, "Memo", DbType.AnsiString, model.Memo);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "AddPersonId", DbType.Guid, model.AddPersonId);
            db.AddInParameter(dbCommand, "AddPerson", DbType.AnsiString, model.AddPerson);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static void Delete(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_Business_NotLitigationInfo ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Business_NotLitigationInfo GetModel(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,ContractId,ContractCode,HasAttachment,HouseAddress,AppCityId,AppCity,AppCompanyId,AppCompany,AppDepartId,AppDepart,AcceptedDate,MailDate,Description,Memo,AddTime,AddPersonId,AddPerson from t_Business_NotLitigationInfo ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            Chenxin.Lib.Business.Entity.t_Business_NotLitigationInfo model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,ContractId,ContractCode,HasAttachment,HouseAddress,AppCityId,AppCity,AppCompanyId,AppCompany,AppDepartId,AppDepart,AcceptedDate,MailDate,Description,Memo,AddTime,AddPersonId,AddPerson ");
            strSql.Append(" FROM t_Business_NotLitigationInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public static DataSet GetList(int PageIndex, int PageSize, String OrderField, string TableName, string StrWhere, string FieldList, string TableFieldList, bool DoCount)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetStoredProcCommand("PagerMultiTable");
            db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            db.AddInParameter(dbCommand, "OrderField", DbType.AnsiString, OrderField);
            db.AddInParameter(dbCommand, "TableName", DbType.AnsiString, TableName);
            db.AddInParameter(dbCommand, "StrWhere", DbType.AnsiString, StrWhere);
            db.AddInParameter(dbCommand, "FieldList", DbType.AnsiString, FieldList);
            db.AddInParameter(dbCommand, "TableFieldList", DbType.AnsiString, TableFieldList);
            db.AddInParameter(dbCommand, "DoCount", DbType.Boolean, DoCount);
            return db.ExecuteDataSet(dbCommand);
        }

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public static List<Chenxin.Lib.Business.Entity.t_Business_NotLitigationInfo> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,ContractId,ContractCode,HasAttachment,HouseAddress,AppCityId,AppCity,AppCompanyId,AppCompany,AppDepartId,AppDepart,AcceptedDate,MailDate,Description,Memo,AddTime,AddPersonId,AddPerson ");
            strSql.Append(" FROM t_Business_NotLitigationInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Chenxin.Lib.Business.Entity.t_Business_NotLitigationInfo> list = new List<Chenxin.Lib.Business.Entity.t_Business_NotLitigationInfo>();
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Business_NotLitigationInfo ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Business.Entity.t_Business_NotLitigationInfo model = new Chenxin.Lib.Business.Entity.t_Business_NotLitigationInfo();
            object ojb;
            ojb = dataReader["RecordId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RecordId = new Guid(ojb.ToString());
            }
            ojb = dataReader["ContractId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ContractId = new Guid(ojb.ToString());
            }
            model.ContractCode = dataReader["ContractCode"].ToString();
            ojb = dataReader["HasAttachment"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.HasAttachment = (int)ojb;
            }
            model.HouseAddress = dataReader["HouseAddress"].ToString();
            ojb = dataReader["AppCityId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AppCityId = new Guid(ojb.ToString());
            }
            model.AppCity = dataReader["AppCity"].ToString();
            ojb = dataReader["AppCompanyId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AppCompanyId = new Guid(ojb.ToString());
            }
            model.AppCompany = dataReader["AppCompany"].ToString();
            ojb = dataReader["AppDepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AppDepartId = new Guid(ojb.ToString());
            }
            model.AppDepart = dataReader["AppDepart"].ToString();
            ojb = dataReader["AcceptedDate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AcceptedDate = (DateTime)ojb;
            }
            ojb = dataReader["MailDate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.MailDate = (DateTime)ojb;
            }
            model.Description = dataReader["Description"].ToString();
            model.Memo = dataReader["Memo"].ToString();
            ojb = dataReader["AddTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddTime = (DateTime)ojb;
            }
            ojb = dataReader["AddPersonId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddPersonId = new Guid(ojb.ToString());
            }
            model.AddPerson = dataReader["AddPerson"].ToString();
            return model;
        }

        #endregion  成员方法
    }
}

